package com.dyc.Adapter;

import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * @author fangtongle
 * @date 2019/5/10 16:39
 * @desc ViewPager适配器
 */
public class ViewpagerAdapter extends PagerAdapter {

    private List<View> pageList;

    public ViewpagerAdapter() {
        super();
    }

    public ViewpagerAdapter(List<View> pageList) {
        super();
        this.pageList = pageList;
    }

    @Override
    public int getCount() {
        return pageList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object o) {
        return view == o;
    }

    // 初始化Item
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(pageList.get(position));
        return pageList.get(position);
    }

    // 销毁Item
    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView(pageList.get(position));
    }
}
